package Controller;

import Model.Teacher;
import Service.Impl.TeacherInterImpl;

import java.util.Scanner;

public class TeacherUI {
    public static int num = 0;
    public static int uId = 1;

    public void TeacherShow() {
        boolean flag = true;
        //定义一个存储老师数据的数组
        Teacher[] teachers = new Teacher[100];

        //实例化通用业务逻辑层对象
        TeacherInterImpl teacherInter = new TeacherInterImpl();

        while (flag) {
            System.out.println("-----请选择到操作菜单-----");
            System.out.println("1.展示所有老师信息");
            System.out.println("2.录入老师信息");
            System.out.println("3.删除老师信息");
            System.out.println("4.修改老师信息");
            System.out.println("0.退出系统");
            Scanner scanner = new Scanner(System.in);
            int menu = scanner.nextInt();
            switch (menu) {
                case 1:
                    // System.out.println("执行老师信息展示的业务逻辑");

                    teacherInter.showTeacher(teachers, TeacherUI.num);
                    break;
                case 2: {
                    //                    System.out.println("执行老师信息录入的业务逻辑");
//                    Teacher person = null;
                    Teacher person = new Teacher();
                    person.setId(uId++);
                    System.out.println("请输入老师姓名");
                    String nameTea = scanner.next();
                    System.out.println("nameTea = " + nameTea);
                    person.setName(nameTea);
                    System.out.println("请输入老师性别");
                    person.setSex(scanner.next());
                    System.out.println("请输入老师年龄");
                    person.setAge(scanner.nextInt());

                    System.out.println("请输入老师科目");
                    person.setSubject(scanner.next());

                    teacherInter.addTeacher(teachers, person);
                }
                break;
                case 3: {
                    System.out.println("请输入你要删除的老师工号");
                    String uid = scanner.next();
                    //找业务逻辑层 Service
                    if (teacherInter.delTeacher(teachers, uid, num)) {
                        System.out.println("删除成功");
                        num--;
                    } else {
                        System.out.println("您要删除的用户不存在！");
                    }

                }
                break;
                case 4: {
                    System.out.println("请输入你要修改的老师工号");
                    String uid = scanner.next();
                    teacherInter.updateTeacher(teachers, uid,num);

                }
                break;
                case 0:
                    System.out.println("退出系统,再见");
                    flag = false;
                    break;
                default:
                    continue;
            }
        }
    }
}
